Add names as best we can to routes read from Google Maps.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 8 Sep 2005 17:24:01 +0000 (17:24 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 8 Sep 2005 17:24:01 +0000 (17:24 +0000)
gpsbabel/defs.h
gpsbabel/google.c
gpsbabel/route.c

index 6e274dafab50b7b68cc5696caad4d9a10581fbd1..1b5b82a6a68d4361e24f987141b9da3f5268af33 100644 (file)
@@ -363,6 +363,7 @@ void route_del_wpt(route_head *rte, waypoint *wpt);
 void route_add_head(route_head *rte);
 void route_del_head(route_head *rte);
 void route_reverse(const route_head *rte_hd);
+waypoint * route_find_waypt_by_name(route_head *rh, const char *name);
 void track_add_head(route_head *rte);
 void track_del_head(route_head *rte);
 void route_disp_all(route_hdr, route_trl, waypt_cb);
index 6ac92f0df8032f2dff6001bdc511a30c525d1703..070fd5af89ced5b29a58877d86d31a0af2346758 100644 (file)
@@ -22,6 +22,8 @@
 static char *encoded_points = NULL;
 static char *encoded_levels = NULL;
 static char *script = NULL;
+static route_head *track_head;
+static void *desc_handle;
 
 FILE *fd;
 
@@ -44,6 +46,7 @@ google_read(void)
 #else
 
 static xg_callback      goog_points, goog_levels, goog_poly_e, goog_script;
+static xg_callback     goog_segment_s, goog_segment;
 
 static 
 xg_tag_mapping google_map[] = {
@@ -51,6 +54,8 @@ xg_tag_mapping google_map[] = {
        { goog_levels,  cb_cdata,       "/page/directions/polyline/levels" },
        { goog_poly_e,  cb_end,         "/page/directions/polyline" },
        { goog_script,  cb_cdata,       "/html/head/script" },
+       { goog_segment_s, cb_start,      "/page/directions/segments/segment" },
+       { goog_segment, cb_cdata,      "/page/directions/segments/segment" },
        { NULL,         0,              NULL }
 };
 
@@ -99,6 +104,36 @@ void goog_levels( const char *args, const char **unused )
        }
 }
 
+static char goog_segname[7];
+
+/*
+ * The segments contain an index into the points array.  We use that
+ * index to find the waypoint and insert a better name for it.
+ */
+void goog_segment_s( const char *args, const char **attrv )
+{
+        const char **avp = &attrv[0];
+        while (*avp) {
+                if (0 == strcmp(avp[0], "pointIndex")) {
+                       snprintf(goog_segname, sizeof(goog_segname), "\\%5.5x", atoi(avp[1]));
+               }
+               avp += 2;
+       }
+
+}
+
+void goog_segment( const char *args, const char **unused )
+{
+       waypoint *wpt_tmp;
+
+       wpt_tmp = route_find_waypt_by_name( track_head, goog_segname);
+       if (wpt_tmp) {
+               xfree(wpt_tmp->shortname);
+               wpt_tmp->shortname = mkshort(desc_handle,args);
+               wpt_tmp->description = xstrdup(args);
+       }
+}
+
 static long decode_goog64( char **str )
 {
        long result = 0;
@@ -128,8 +163,8 @@ void goog_poly_e( const char *args, const char **unused )
        long level2 = -9999;
         char *str = encoded_points;
        char *lstr = encoded_levels;
-       
-       route_head *track_head = route_head_alloc();
+
+       track_head = route_head_alloc();
        route_add_head(track_head);
 
        while ( str && *str ) 
@@ -179,6 +214,9 @@ void goog_poly_e( const char *args, const char **unused )
 void
 google_rd_init(const char *fname)
 {
+       desc_handle = mkshort_new_handle();
+       setshort_length(desc_handle, 12);
+
        xml_init(fname, google_map, "ISO-8859-1" );
 }
 
@@ -209,6 +247,7 @@ void
 google_rd_deinit(void)
 {
        xml_deinit();
+       mkshort_del_handle(desc_handle);
 }
 
 ff_vecs_t google_vecs = {
index 90c5a09f235321b266d3de1217109bc3cb5b3e53..191ec13d5da005feaa750ad9ef08bbaf3627961f 100644 (file)
@@ -108,6 +108,20 @@ route_add_wpt(route_head *rte, waypoint *wpt)
        }
 }
 
+waypoint *
+route_find_waypt_by_name( route_head *rh, const char *name )
+{
+       queue *elem, *tmp;
+
+       QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
+               waypoint *waypointp = (waypoint *) elem;
+               if (0 == strcmp(waypointp->shortname, name)) {
+                       return waypointp;
+               }
+       }
+       return NULL;
+}
+
 void 
 route_del_wpt( route_head *rte, waypoint *wpt)
 {